/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mlbs.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author mckd87
 */
@Entity
@Table(name = "preferences")
@NamedQueries({@NamedQuery(name = "Preferences.findByKeyName", query = "SELECT p FROM Preferences p WHERE p.keyName = :keyName"), @NamedQuery(name = "Preferences.findByCacheFlag", query = "SELECT p FROM Preferences p WHERE p.cacheFlag = :cacheFlag"), @NamedQuery(name = "Preferences.findByPrefId", query = "SELECT p FROM Preferences p WHERE p.prefId = :prefId"), @NamedQuery(name = "Preferences.findByValue", query = "SELECT p FROM Preferences p WHERE p.value = :value")})
public class Preferences implements Serializable {
    private static final long serialVersionUID = 1L;
    @Column(name = "keyName")
    private String keyName;
    @Column(name = "cacheFlag")
    private Boolean cacheFlag;
    @Id
    @Column(name = "prefId", nullable = false)
    private Integer prefId;
    @Column(name = "value")
    private String value;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "appId", fetch=FetchType.EAGER)
    private Collection<Pagecache> pagecacheCollection;
    @JoinColumn(name = "typeId", referencedColumnName = "typeId")
    @ManyToOne
    private Type typeId;
    @JoinColumn(name = "userId", referencedColumnName = "userId")
    @ManyToOne
    private Usertable userId;
    @JoinColumn(name = "deviceid", referencedColumnName = "deviceid")
    @ManyToOne
    private Device deviceid;
    @JoinColumn(name = "appId", referencedColumnName = "appId")
    @ManyToOne
    private Application appId;
    @JoinColumn(name = "criteriaId", referencedColumnName = "criteriaId")
    @ManyToOne
    private Criteria criteriaId;
    @JoinColumn(name = "geoId", referencedColumnName = "geoId")
    @ManyToOne
    private Geodb geoId;

    public Preferences() {
        pagecacheCollection = new ArrayList<Pagecache>();
    }

    public Preferences(Integer prefId) {
        this.prefId = prefId;
        pagecacheCollection = new ArrayList<Pagecache>();
    }

    public String getKeyName() {
        return keyName;
    }

    public void setKeyName(String keyName) {
        this.keyName = keyName;
    }

    public Boolean getCacheFlag() {
        return cacheFlag;
    }

    public void setCacheFlag(Boolean cacheFlag) {
        this.cacheFlag = cacheFlag;
    }

    public Integer getPrefId() {
        return prefId;
    }

    public void setPrefId(Integer prefId) {
        this.prefId = prefId;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Collection<Pagecache> getPagecacheCollection() {
        return pagecacheCollection;
    }

    public void setPagecacheCollection(Collection<Pagecache> pagecacheCollection) {
        this.pagecacheCollection = pagecacheCollection;
    }

    public Type getTypeId() {
        return typeId;
    }

    public void setTypeId(Type typeId) {
        this.typeId = typeId;
    }

    public Usertable getUserId() {
        return userId;
    }

    public void setUserId(Usertable userId) {
        this.userId = userId;
    }

    public Device getDeviceid() {
        return deviceid;
    }

    public void setDeviceid(Device deviceid) {
        this.deviceid = deviceid;
    }

    public Application getAppId() {
        return appId;
    }

    public void setAppId(Application appId) {
        this.appId = appId;
    }

    public Criteria getCriteriaId() {
        return criteriaId;
    }

    public void setCriteriaId(Criteria criteriaId) {
        this.criteriaId = criteriaId;
    }

    public Geodb getGeoId() {
        return geoId;
    }

    public void setGeoId(Geodb geoId) {
        this.geoId = geoId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (prefId != null ? prefId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Preferences)) {
            return false;
        }
        Preferences other = (Preferences) object;
        if ((this.prefId == null && other.prefId != null) || (this.prefId != null && !this.prefId.equals(other.prefId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.mlbs.entity.Preferences[prefId=" + prefId + "]";
    }

}
